﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace DefCore.AI.Pathing
{
    public struct Waypoint
    { 
        //Methods
		private Vector2 _WaypointPosition;
        public Vector2 WaypointPosition
		{
			get { return _WaypointPosition; }
			set { _WaypointPosition = value; }
		}

        //cTor
        public Waypoint(Vector2 position)
        {
            _WaypointPosition = position;
        }

        public Vector2 DistanceTo(Waypoint b)
        {
            return GetDistanceBetween(this, b);
        }
        public float AngleTo(Waypoint b)
        {
            return GetAngleBetween(this, b);
        }

        //
        public static Waypoint operator -(Waypoint a, Waypoint b)
        {
            return new Waypoint(a._WaypointPosition - b._WaypointPosition);
        }
        public static implicit operator Vector2(Waypoint a)
        {
            return a._WaypointPosition;
        }
        public static implicit operator Waypoint(Vector2 a)
        {
            return new Waypoint(a);
        } 

        //Statics
        public static float GetAngleBetween(Waypoint a, Waypoint b)
        {
            return (float)Math.Atan2(b._WaypointPosition.Y - a._WaypointPosition.Y, b._WaypointPosition.X - a._WaypointPosition.X)
                 + MathHelper.ToRadians(90);
        }
        public static Vector2 GetDistanceBetween(Waypoint a, Waypoint b)
        {
            return b - a;
        }
    }
}
